package com.codedancer.campus.enums;

import cn.hutool.core.util.ObjectUtil;
import com.codedancer.campus.common.enums.CodeDbEnum;
import com.fasterxml.jackson.annotation.JsonValue;

/**
 * @Author codeworld 商品状态
 **/
public enum CommodityStatus implements CodeDbEnum {

    PENDING_REVIEW(1, "待审核"),
    NOT_PASS(2, "未通过"),
    ON_SHELF(3, "上架"),
    OFF_SHELF(4, "下架");

    /**
     * 对应的值
     */
    @JsonValue
    private final Integer value;

    /**
     * 对应的名称
     */
    private final String name;

    CommodityStatus(Integer value, String name) {
        this.value = value;
        this.name = name;
    }

    public static CommodityStatus fromValue(Integer value) {
        for (CommodityStatus commodityStatus : CommodityStatus.values()) {
            if (ObjectUtil.equal(commodityStatus.getValue(), value)) {
                return commodityStatus;
            }
        }
        return null;
    }

    @Override
    public Integer getValue() {
        return value;
    }

    public String getName() {
        return name;
    }
}
